Safe Units
SIベースの単位系の実装を提供するが、ユーザが独自の単位系を作成できる code:ts
import { bars, kilograms, Measure, meters, milli, seconds } from "safe-units";
const width = Measure.of(3, meters);
const height = Measure.of(4, meters);
const area = width.times(height).scale(0.5);
const hypot = Measure.sqrt(width.squared().plus(height.squared())); // 5 m
const mass = Measure.of(30, kilograms);
const mps2 = meters.per(seconds.squared());
const acceleration = Measure.of(9.8, mps2);
const force = mass.times(acceleration); // 294 N
const pressure = force.over(area); // 49 Pa
const maxPressure = Measure.of(0.5, milli(bars)); // 0.5 mbar
pressure.lt(maxPressure) // true
method chain styleかぁ〜
ちょっときつそう